# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=icmpsh
pkgver=12.82caf34
pkgrel=6
pkgdesc='Simple reverse ICMP shell.'
groups=('blackarch' 'blackarch-backdoor' 'blackarch-networking')
arch=('any')
url='https://github.com/inquisb/icmpsh'
license=('custom:unknown')
depends=('python2' 'perl')
makedepends=('git')
source=("git+https://github.com/inquisb/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

build() {
  cd $pkgname

  gcc -o icmpsh-m icmpsh-m.c
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md

  rm README.md

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/icmpsh-m" << EOF
#!/bin/sh
exec /usr/share/$pkgname/icmpsh-m "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/icmpsh-m"

  cat > "$pkgdir/usr/bin/icmpsh-m-py" << EOF
#!/bin/sh
exec python2 /usr/share/$pkgname/icmpsh_m.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/icmpsh-m-py"

  cat > "$pkgdir/usr/bin/icmpsh-m-pl" << EOF
#!/bin/sh
exec perl /usr/share/$pkgname/icmpsh-m.pl "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/icmpsh-m-pl"
}

